package com.foreveross.fetl.application.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dayatang.querychannel.support.Page;
import com.foreveross.fetl.application.ExcelInfoApplication;
import com.foreveross.fetl.common.application.BaseApplicationImpl;
import com.foreveross.fetl.core.domain.task.ExcelInfoEntity;
import com.foreveross.fetl.vo.ExcelInfoVO;

@Transactional(value="transactionManagerOracle")
@Service("excelInfoApplication")
public class ExcelInfoApplicationImpl extends BaseApplicationImpl implements
		ExcelInfoApplication {

	@Override
	public List<ExcelInfoVO> findAll() {
		List<ExcelInfoVO> listVO=new ArrayList<ExcelInfoVO>();
		ExcelInfoEntity entity =new ExcelInfoEntity();
		List<ExcelInfoEntity> list =entity.findAll();
		if(null!=list && list.size()>0){
			for(ExcelInfoEntity en :list){
				ExcelInfoVO vo = this.changeToVO(en);
				listVO.add(vo);
			}
		}
	
		return listVO;
	}

	private ExcelInfoVO changeToVO(ExcelInfoEntity entity) {
		ExcelInfoVO vo =new ExcelInfoVO();
		vo.setId(entity.getId());
		vo.setCode(entity.getCode());
		vo.setDateType(entity.getDateType());
		vo.setName(entity.getName());
		vo.setPath(entity.getPath());
		vo.setUploadDate(entity.getUploadDate());
		vo.setFileType(entity.getFileType());
		vo.setType(entity.getType());
		return vo;
	}

	@Override
	public void saveOrUpdate(ExcelInfoVO excelInfovo) {
		ExcelInfoEntity entity =new ExcelInfoEntity();
		entity=this.changeToEntity(excelInfovo);
		entity.saveOrUpdate(entity);

	}

	private ExcelInfoEntity changeToEntity(ExcelInfoVO excelInfovo) {
		ExcelInfoEntity entity =new ExcelInfoEntity();
		entity.setId(excelInfovo.getId());
		entity.setCode(excelInfovo.getCode());
		entity.setDateType(excelInfovo.getDateType());
		entity.setUploadDate(excelInfovo.getUploadDate());
		entity.setName(excelInfovo.getName());
		entity.setPath(excelInfovo.getPath());
		entity.setFileType(excelInfovo.getFileType());
		entity.setType(excelInfovo.getType());
		return entity;
	}

	@Override
	public void delete(ExcelInfoVO excelInfovo) {
		ExcelInfoEntity entity =new ExcelInfoEntity();
		entity=this.changeToEntity(excelInfovo);
		entity.delete(entity);
	}

	@Override
	public ExcelInfoVO findById(Long id) {
		ExcelInfoEntity entity =new ExcelInfoEntity();
		entity=entity.findById(id);
		ExcelInfoVO vo =this.changeToVO(entity);
		return vo;
	}

	@Override
	public Page<ExcelInfoVO> pageForExcelInfo(String code, int pageNo,
			int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<ExcelInfoVO> findByTime(String date,String fileType,Integer type) {
		List<ExcelInfoVO> listVO=new ArrayList<ExcelInfoVO>();
		ExcelInfoEntity entity =new ExcelInfoEntity();
		List<ExcelInfoEntity> list =entity.findByTime(date,fileType,type);
		if(null!=list && list.size()>0){
			for(ExcelInfoEntity en :list){
				ExcelInfoVO vo = this.changeToVO(en);
				listVO.add(vo);
			}
		}
	
		return listVO;
	}

	@Override
	public List<ExcelInfoVO> findBycode(String code, String date,String fileType,Integer type) {
		List<ExcelInfoVO> listVO=new ArrayList<ExcelInfoVO>();
		ExcelInfoEntity entity =new ExcelInfoEntity();
		List<ExcelInfoEntity> list =entity.findBycode(code, date,fileType,type);
		if(null!=list && list.size()>0){
			for(ExcelInfoEntity en :list){
				ExcelInfoVO vo = this.changeToVO(en);
				listVO.add(vo);
			}
		}
	
		return listVO;
	}

	@Override
	public List<ExcelInfoVO> findBycodeAndTime(String code, String date,String fileType,Integer type) {
		List<ExcelInfoVO> listVO=new ArrayList<ExcelInfoVO>();
		ExcelInfoEntity entity =new ExcelInfoEntity();
		List<ExcelInfoEntity> list =entity.findBycodeAndTime(code, date,fileType,type);
		if(null!=list && list.size()>0){
			for(ExcelInfoEntity en :list){
				ExcelInfoVO vo = this.changeToVO(en);
				listVO.add(vo);
			}
		}
	
		return listVO;
	}

	@Override
	public ExcelInfoVO findByName(String name,String fileType,Integer type) {
		ExcelInfoEntity entity =new ExcelInfoEntity();
		entity=entity.findByName(name,fileType,type);
		if(null!=entity && entity.getName()!=null){
			return this.changeToVO(entity);
		}
		return null;
	}

}
